﻿using System;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Windows;

namespace Organizer.Model
{
    [Table]
    public class Settings : Base<Settings>
    {
        [Column(IsPrimaryKey = true, DbType = "UniqueIdentifier NOT NULL", CanBeNull = false, AutoSync = AutoSync.OnInsert, UpdateCheck = UpdateCheck.Never)]
        public Guid Id { get; private set; }

        [Column]
        internal Guid _userId;
        private EntityRef<User> _user;
        [Association(Storage = "_user", ThisKey = "_userId", OtherKey = "Id", IsForeignKey = true)]
        public User User
        {
            get { return _user.Entity; }
            set
            {
                NotifyPropertyChanging(() => this.User);
                _user.Entity = value;
                NotifyPropertyChanged(() => this.User);
                if (value != null) _userId = value.Id;
            }
        }


        public Settings()
        {
            Id = Guid.NewGuid();
        }

        public Settings(User usr)
            : this()
        {
            Id = Guid.NewGuid();
            User = usr;
        }

        //private TextWrapping _tw;

        //public TextWrapping TextWrap
        //{
        //    get { return _tw; }
        //    set { _tw = value; NotifyPropertyChanged("TextWrap"); NotifyPropertyChanged("TextWrapBool"); }
        //}

        private bool _studentSortByGroups;
        [Column]
        public bool StudentSortByGroups
        {
            get { return _studentSortByGroups; }
            set
            {
                if (_studentSortByGroups == value)
                { return; }
                NotifyPropertyChanging(() => this.StudentSortByGroups);
                _studentSortByGroups = value;
                NotifyPropertyChanged(() => this.StudentSortByGroups);
            }
        }

        private bool _createLessonMode;
        //[Column]
        public bool CreateLessonMode
        {
            get { return _createLessonMode; }
            set
            {
                if (_createLessonMode == value)
                { return; }
                NotifyPropertyChanging(() => this.CreateLessonMode);
                _createLessonMode = value;
                NotifyPropertyChanged(() => this.CreateLessonMode);
            }
        }
    }
}
